package com.lb.sort;

/**
 * @ClassName SelectionSort
 * @Author LB
 * @Date 2022/1/13 14:29
 **/
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {5,8,64,68,21};
        int len = arr.length;
        int minIndex, temp;
        //排序趟数
        for (int i = 0; i < len - 1; i++) {
            minIndex = i;
            for (int j = i + 1; j < len; j++) {
                if (arr[j] < arr[minIndex]) {     // 寻找最小的数
                    minIndex = j;                 // 将最小数的索引保存
                }
            }
            temp = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = temp;
            for (int i1 : arr) {
                System.out.print(i1+" ");
            }
            System.out.println();
        }
    }
}